package com.example.propertymanagement.entity;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = true)  // 自动应用到所有 CommunityStatus 字段
public class CommunityStatusConverter implements AttributeConverter<CommunityStatus, String> {

    @Override
    public String convertToDatabaseColumn(CommunityStatus attribute) {
        if (attribute == null) return null;
        return attribute.getLabel();  // 将枚举转换为数据库存储的中文值
    }

    @Override
    public CommunityStatus convertToEntityAttribute(String dbData) {
        if (dbData == null) return null;
        return CommunityStatus.fromLabel(dbData);  // 将数据库中的中文值转换为枚举
    }
}